package com.gitee.maskit.data.redis;

import org.apache.commons.pool2.impl.GenericObjectPool;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnection;
import org.springframework.data.redis.core.RedisOperations;
import redis.clients.jedis.Jedis;

@Order
@Configuration
public class MaskitRedisAutoConfiguration {

    @Bean
    @ConditionalOnClass({JedisConnection.class, RedisOperations.class, Jedis.class, GenericObjectPool.class})
    public RedisTemplates redisTemplateFactory() {
        return new RedisTemplates();
    }

    @Bean
    @ConditionalOnMissingBean
    public ObjectProvider<RedisSentinelConfiguration> redisSentinelConfigurationObjectProvider() {
        return NopObjectProvider.get();
    }

    @Bean
    @ConditionalOnMissingBean
    public ObjectProvider<RedisClusterConfiguration> redisClusterConfigurationObjectProvider() {
        return NopObjectProvider.get();
    }
}
